//
//  DYZShowController.m
//  DYZCars
//
//  Created by 李凯 on 16/8/18.
//  Copyright © 2016年 MF. All rights reserved.
//

#import "DYZShowController.h"
#import "Masonry.h"
#import "DYZNewLaunchCell.h"
#import "DYZCarShowModel.h"

@interface DYZShowController () <UITableViewDataSource>

@property (nonatomic, strong) NSMutableArray *carShowArr;
@property (nonatomic, strong) UITableView *tableView;

@end

static NSString *newLaunchCellID = @"newLaunchCellID";

@implementation DYZShowController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupTableView];
    [self loadData];
    
}

- (void)loadData
{
    NSString *path = [[NSBundle mainBundle]pathForResource:@"CarShow.plist" ofType:nil];
    NSArray *arr = [NSArray arrayWithContentsOfFile:path];
    for (NSDictionary *dict in arr) {
        DYZCarShowModel *model = [[DYZCarShowModel alloc]init];
        [model setValuesForKeysWithDictionary:dict];
        //        NSLog(@"%@", model);
        [self.carShowArr addObject:model];
    }
    [self.tableView reloadData];
}

- (void) setupTableView
{
    UITableView *tableView = [[UITableView alloc]init];
    [tableView registerNib:[UINib nibWithNibName:@"DYZNewLaunchCell" bundle:nil] forCellReuseIdentifier:newLaunchCellID];
    tableView.dataSource = self;
    tableView.rowHeight = 64;
    [self.view addSubview:tableView];
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    self.tableView = tableView;
    //隐藏多余的tableViewCell
    tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.carShowArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DYZNewLaunchCell *cell = [tableView dequeueReusableCellWithIdentifier:newLaunchCellID forIndexPath:indexPath];
    cell.model = self.carShowArr[indexPath.row];
    return cell;
}

//懒加载
-(NSMutableArray *)carShowArr
{
    if(_carShowArr == nil)
    {
        _carShowArr = [NSMutableArray array];
    }
    return _carShowArr;
}



@end
